<template>
  <div v-if="error" class="error-boundary">
    <el-result
      icon="error"
      :title="t('error.title')"
      :sub-title="t('error.message')"
    >
      <template #extra>
        <el-button type="primary" @click="retry">{{ t('error.retry') }}</el-button>
      </template>
    </el-result>
  </div>
  <slot v-else></slot>
</template>

<script setup>
import { ref, onErrorCaptured } from 'vue'
import { useI18n } from 'vue-i18n'

const { t } = useI18n()
const error = ref(null)

const retry = () => {
  error.value = null
}

onErrorCaptured((err) => {
  error.value = err
  return false // 阻止错误继续传播
})
</script>

<style scoped>
.error-boundary {
  padding: 20px;
  text-align: center;
}
</style> 